package com.example.coiltest

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.ImageView
import android.widget.Spinner
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import coil.load
import coil.transform.CircleCropTransformation
import coil.transform.RoundedCornersTransformation
import jp.wasabeef.transformers.coil.CropCenterTransformation
import jp.wasabeef.transformers.coil.CropCircleWithBorderTransformation


class MainActivity : AppCompatActivity() {

    val url = "https://i.ibb.co/ry6q2M6/lol-21.jpg"

    lateinit var imageview: ImageView
    lateinit var spinner: Spinner
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        imageview = findViewById(R.id.imageView)
        spinner = findViewById(R.id.spinner)



        spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
            override fun onItemSelected(adapterView: AdapterView<*>, view: View?, i: Int, l: Long) {
                when (i) {
                    0 -> {
                        imageview.load(url)

                    }
                    1 -> {
                        imageview.load(url) {
                            crossfade(true)
                        }

                    }
                    2 -> {
                        imageview.load(url) {
                            crossfade(2000)
                        }

                    }
                    3 -> {
                        imageview.load(url) {
                            placeholder(R.drawable.ic_launcher_background)
                            crossfade(3000)
                        }
                    }

                    4 -> {

                        imageview.load(url) {
                            error(R.drawable.bg_patrol_record_top)
                        }
                    }

                    5 -> {
                        imageview.load(url) {
                            transformations(CircleCropTransformation())

                        }
                    }
                    6 -> {
                        imageview.load(url) {
                            transformations(
                                RoundedCornersTransformation(
                                    topRight = 10f,
                                    topLeft = 10f,
                                    bottomLeft = 10f,
                                    bottomRight = 10f
                                )
                            )
                        }

                    }
                    7 -> {
                        imageview.load(R.drawable.bg_patrol_record_top) {
                            transformations(
                                CropCenterTransformation(),
                                CropCircleWithBorderTransformation(4, Color.rgb(0, 191, 255))
                            )

                    }
                    }
                    else -> {}
                }

            }

            override fun onNothingSelected(adapterView: AdapterView<*>?) {}
        }

    }
}